// createRouter方法，作用是用来创建router实例对象，相当于new router()
// createWebHashHistory方法，用来创建哈希模式的路由实例
import { createRouter, createWebHashHistory } from 'vue-router'

import layout from '@/views/layout/'
import category from '@/views/category/'
import login from '@/views/login/'
import home from '@/views/home/'
import goods from '@/views/goods/'
import cart from '@/views/cart/'
import settlement from '@/views/settlement/'
// 配置path和component配置项
const routes = [
  {
    path: '/',
    component: layout,
    children: [
      {
        path: '/settlement',
        component: settlement
      },
      {
        path: '/cart',
        component: cart
      },
      {
        path: '/good/:id',
        component: goods
      },
      {
        path: 'category/:id',
        component: category
      },
      {
        path: '', // path置空，作为默认的二级路由
        component: home
      }
    ]
  },
  {
    path: '/login',
    component: login
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

export default router
